
package poker.plans.croupier;

import java.util.List;

import jadex.adapter.fipa.*;
import jadex.runtime.*;

import poker.beliefs.Table;

/**
 *  Plan to program an event of "time for registering expired"
 */

public class RegisterPeriodPlan extends Plan {

	public void body() {
		// Set the register deadline in the belief base
		long period = (Long)getBeliefbase().getBelief("register_period").getFact();
		long now = System.currentTimeMillis();
		getBeliefbase().getBelief("deadline").setFact(new Long(now + period));
		
		System.out.println("CROUPIER - Beginning of register time");
		
		// Wait for the deadline to be reached
		ICondition condition = getCondition("register_time_expired");
		waitForCondition(condition);
		
		System.out.println("CROUPIER - Register time expired");
		
		// Pass to preflop round, no more registers allowed
		Table t = (Table) getBeliefbase().getBelief("table").getFact();
		t.nextRound();
        
		//Notify players about other players
		IMessageEvent msg = createMessageEvent("inform_players_ids");
		msg.setContent(t.getPlayers());
		msg.getParameterSet(SFipa.RECEIVERS).addValues(t.getPlayers());
		sendMessage(msg);

		System.out.print("CROUPIER - Let's begin the game with the players:" + t.getPlayers().length);
		for (AgentIdentifier aId : t.getPlayers()) {
			System.out.print(" " + aId.getName());
		}
				
		System.out.println("");
		
        // Start playing the hand, create the goal to begin dealing cards
		//Update beliefs
		getBeliefbase().getBelief("table").setFact(t);
	}
	
}
